package com.ujoku.service.impl;

import com.labillusion.core.database.base.mybatis.dao.BaseDao;
import com.labillusion.core.database.base.mybatis.service.base.impl.BaseServiceImpl;
import com.ujoku.dao.OrderItemDao;
import com.ujoku.domain.OrderItem;
import com.ujoku.service.CdnService;
import com.ujoku.service.OrderItemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by Andy.Lian on 2014/11/4.
 */
@Service
public class OrderItemServiceImpl extends BaseServiceImpl<OrderItem> implements OrderItemService<OrderItem> {
    @Autowired
    private OrderItemDao orderGoodsDao;

    @Autowired
    private CdnService cdnService;

    @Override
    protected BaseDao<OrderItem> getBaseDao() {
        return orderGoodsDao;
    }

    @Override
    public List<OrderItem> selectByOrderId(String orderId){
        Map<String,Object> query = new HashMap<>();
        query.put("orderId", orderId);

        List<OrderItem> orderItemList =  super.selectList(query);
        orderItemList.forEach(i->i.setSmallImage(cdnService.buildGoodsImage(i.getGoodsId(), CdnService.Goods_Small, i.getGoodsUpdateTime().getTime())));
        orderItemList.forEach(i->i.setTotal());

        return orderItemList;
    }

    @Override
    public List<OrderItem> selectCellarSellRecord(Map<String,Object> query){
        List<OrderItem> orderItemList = orderGoodsDao.selectCellarSellRecord(query);
        orderItemList.forEach(i->i.setSmallImage(cdnService.buildGoodsImage(i.getGoodsId(), CdnService.Goods_Small, i.getGoodsUpdateTime().getTime())));
        orderItemList.forEach(i->i.setTotal());

        return orderItemList;
    }

    @Override
    public int selectSalesCount(Map<String,Object> query){
        return orderGoodsDao.selectSalesCount(query);
    }
}
